package com.ruoyi.web.controller.zhhq;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zhhq.domain.Cartype;
import com.ruoyi.zhhq.service.ICartypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆类别Controller
 * 
 * @author Anthony Lu
 * @date 2022-11-09
 */
@RestController
@RequestMapping("/zhhq/cartype")
public class CartypeController extends BaseController
{
    @Autowired
    private ICartypeService cartypeService;

    /**
     * 查询车辆类别列表
     */
    @PreAuthorize("@ss.hasPermi('zhhq:cartype:list')")
    @GetMapping("/list")
    public TableDataInfo list(Cartype cartype)
    {
        startPage();
        List<Cartype> list = cartypeService.selectCartypeList(cartype);
        return getDataTable(list);
    }

    /**
     * 导出车辆类别列表
     */
    @PreAuthorize("@ss.hasPermi('zhhq:cartype:export')")
    @Log(title = "车辆类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Cartype cartype)
    {
        List<Cartype> list = cartypeService.selectCartypeList(cartype);
        ExcelUtil<Cartype> util = new ExcelUtil<Cartype>(Cartype.class);
        util.exportExcel(response, list, "车辆类别数据");
    }

    /**
     * 获取车辆类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('zhhq:cartype:query')")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") String typeId)
    {
        return AjaxResult.success(cartypeService.selectCartypeByTypeId(typeId));
    }

    /**
     * 新增车辆类别
     */
    @PreAuthorize("@ss.hasPermi('zhhq:cartype:add')")
    @Log(title = "车辆类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cartype cartype)
    {
        return toAjax(cartypeService.insertCartype(cartype));
    }

    /**
     * 修改车辆类别
     */
    @PreAuthorize("@ss.hasPermi('zhhq:cartype:edit')")
    @Log(title = "车辆类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cartype cartype)
    {
        return toAjax(cartypeService.updateCartype(cartype));
    }

    /**
     * 删除车辆类别
     */
    @PreAuthorize("@ss.hasPermi('zhhq:cartype:remove')")
    @Log(title = "车辆类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable String[] typeIds)
    {
        return toAjax(cartypeService.deleteCartypeByTypeIds(typeIds));
    }
}
